package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.entity.Member;

/**
 * @author mufeiyu
 */
public class CarStockRegisterInfoAjaxAction extends TmsAjaxAction{
	private Logger logger = Logger.getLogger(CarStockRegisterInfoAjaxAction.class);
	private static final String SERIAL = "serial";
	private static final String MEMBERID = "memberId";
	private static final String REGISTERSTATUSNUM = "registerStatusNum";

	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		String serial = request.getParameter(SERIAL);
		String memberId = request.getParameter(MEMBERID);
		String registerStatusNum = request.getParameter(REGISTERSTATUSNUM);
		Car car = Car.getInstance();
		//会员数据
		Member member = Member.getInstance();
		boolean checkResult = car.isChangedStockStatus(serial, Integer.valueOf(registerStatusNum));
		String responseText = "0";
		if(checkResult == true)
		{
			responseText = "1";
		} else if (Integer.valueOf(registerStatusNum) == 1){
			member = member.findCarScoreByMemberId(memberId);
			if(member.getUsedCarPort() + 1 > member.getCarPort())
			{
				responseText = "2";
			}
		}
		responseValues(response, responseText, TEXT);
		logger.debug(this.getClass().getName() + "#doAction was completed.");		
	}
}
